<?php
/**
 * Created by PhpStorm.
 * User: 牛赞赞
 * Date: 2020/12/23
 * Time: 17:20
 */

namespace App\Model;


class UserToken extends Model
{
    protected   $table = 'user_token';
    protected   $fillable = ['user_id', 'token', 'createtime', 'expiretime'];
    public      $timestamps = false;

    public static function checkUser($token){
        try{
            $res = self::query()->where('token',$token)->first();
            if(isset($res->expiretime)){
                if(time() < $res->expiretime){
                    return ['code'=>0,'msg'=>'ok','data'=>['uid'=>$res->user_id]];
                }else{
                    return ['code'=>3,'msg'=>'登录过期'];
                }
            }else{
                return ['code'=>2,'msg'=>'未找到用户'];
            }
        }catch (\Exception $e){
            return ['code'=>1,'msg'=>$e->getMessage()];
        }
    }

}